/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.backup.user;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Ahmed Salem
 */
public final class PasswordService {

    public String getMD5Hash(String value)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {

        final StringBuilder sbMd5Hash = new StringBuilder();
        final MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(value.getBytes("UTF-8"));

        final byte data[] = m.digest();

        for (byte element : data) {
            sbMd5Hash.append(Character.forDigit((element >> 4) & 0xf, 16));
            sbMd5Hash.append(Character.forDigit(element & 0xf, 16));
        }

        return sbMd5Hash.toString();
    }
}
